from selenium.webdriver.support import expected_conditions as EC

from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait

from commom.Utils import WebChatDriver


class WebChatDetail:
    driver = ""
    url = ""
    def __init__(self):
        self.driver = WebChatDetail.driver
        self.url = "http://127.0.0.1:8080/client.html"

    #测试成功登录下的元素
    def CheckSuccElement(self):
        self.driver.find_element(By.CSS_SELECTOR,"body > div.client-container > div > div.right > div.title")
        self.driver.find_element(By.CSS_SELECTOR,"body > div.client-container > div > div.right > div.ctrl > button")
    #测试非法登录下的弹窗
    def CheckFailElement(self):
        wait = WebDriverWait(self.driver, 5)
        # 等待直到页面出现警告框，满足这个条件才会继续往下执行
        wait.until(EC.alert_is_present())
        # 切换到弹窗
        alert = self.driver.switch_to.alert

        text = alert.text
        alert.accept()

        assert "当前用户未登录!" == text
        WebChatDriver.getScreeShot()
        #检查是否回到主页
        self.driver.find_element(By.CSS_SELECTOR," body > div.login - container > div > h3")
